import { expect } from '@jest/globals';

import { initExecuteCommand, runHvigorAsync } from '../../common/common';
import {
  AbilityType,
  APIType,
  APIVersion,
  CaseLevel,
  IsEnable,
  LanguageType,
  ModuleTemplateType,
  RuntimeOSType,
  SDKType, SignType,
} from '../../plugins/project-builder/models/constants';
import { TestCaseBuilder } from '../../plugins/task-builder/task-case-builder';
import { ProjectBuildOption, TestCaseFun } from '../../plugins/task-builder/test-case';
import { TestTaskOptionBuilder } from '../../plugins/task-builder/test-task-option';

const projectBuilderOption: ProjectBuildOption = {
  template: {
    sdk: SDKType.Single,
    runtimeOS: RuntimeOSType.HarmonyOS,
    apiVersion: APIVersion.API11,
    apiType: APIType.STAGE,
    language: LanguageType.ArkTs,
    abilityType: AbilityType.Application,
    entryTemplateType: ModuleTemplateType.EmptyAbility
  }
};

const testFun: TestCaseFun = async (project, taskConfig, record) => {
  const projectRoot = project.projectRootPath();
  const commands = initExecuteCommand({
    tasks: '--help'
  });

  // 执行两遍，第一遍清除，第二遍 没有文件可以清除。
  const result = await runHvigorAsync(projectRoot, commands);
  record.addStep('step', result);
  expect(result.stdout).toContain('Usage: hvigor [taskNames...] <options...>');
  expect(result.stdout).toContain('-v, --version');
  expect(result.stdout).toContain('-e, --error');
  expect(result.stdout).toContain('-w, --warn');
  expect(result.stdout).toContain('-i, --info');
  expect(result.stdout).toContain('-d, --debug');
  expect(result.stdout).toContain('-p, --prop <value>');

  expect(result.stdout).toContain('-i, --info');
  expect(result.stdout).toContain('-i, --info');
  expect(result.stdout).toContain('-i, --info');
  expect(result.stdout).toContain('-i, --info');
  expect(result.stdout).toContain('-i, --info');
  expect(result.stdout).toContain('-i, --info');
};

TestCaseBuilder.builder()
  .caseName('help Command')
  .description('hvigorw --help')
  .projectBuilderOption(projectBuilderOption)
  .taskConfig(TestTaskOptionBuilder.builder().sign(SignType.NoSign).ohpmInstall(IsEnable.DisAble).caseLevel(CaseLevel.L3).build())
  .testFun(testFun)
  .load();
